﻿using System;
using System.Configuration;
using Types.Enumerations;

namespace Contracts.Caching
{
    public static class CacheProvider
    {
        private static ICacheProvider mInstance;
        private static CacheProviderSettings mProvSettings;

        public static ICacheProvider Provider
        {
            get { return mInstance; }
        }

        public static CacheProviderSettings ProviderSettings
        {
            get { return mProvSettings; }
        }

        static CacheProvider()
        {
            // initialize settings. 

            mProvSettings = (CacheProviderSettings)ConfigurationManager.GetSection("CacheProviderSettings");
            InitializeCacheProvider();

        }

        private static void InitializeCacheProvider()
        {
            if (mProvSettings.ProviderName == EnumCacheProviders.CustomInMemoryCache  )
            {
                mInstance = CustomInMemoryCache.GetProviderInstance;
            }
            else if (mProvSettings.ProviderName == EnumCacheProviders.FileDependentCache)
            {
                mInstance = FileDependentCacheProvider.GetProviderInstance;
            }
            else if (mProvSettings.ProviderName == EnumCacheProviders.VelocityCache )
            {
                mInstance = AppfabricCacheProvider.GetProviderInstance;
            }
            else
            {
                throw new ArgumentException();
            }


        }
    }
}
